<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Set
 *
 * @author josema
 */
class Set {
    public $values = array ();

    function  __construct($array) {
        $this->values = $array;
    }

    public function sum ($name) {
        $result = 0;
        foreach ($this->values as $value) {
            $result += $value->$name;
        }
        return $result;
    }

    public function sumWhereAttrEQ ($name, $att, $val) {
        $result = 0;
        foreach ($this->values as $value) {
            if ($value->$att == $val)
                $result += $value->$name;
        }
        return $result;
    }

    public function sumWhereAttrNE ($name, $att, $val) {
        $result = 0;
        foreach ($this->values as $value) {
            if ($value->$att != $val)
                $result += $value->$name;
        }
        return $result;
    }
}
?>
